package com.batchap.classes;

import java.io.IOException;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.batchap.photoframe.PhotoFrameCanvas;

public class MyMenu {

	// public enum MenuType { Main, Result, Sound, Complete };
	// public MenuType Type;
	PhotoFrameCanvas photoCanvas;

	public static final int Main = 0;
	public static final int HelpScreen = 1;
	public static final int AboutScreen = 2;

	public int Type;
	public MySprite Kid, Flower, Exit, About, Help, Back;
	public MySprite Background, BackgroundHelpAbout;

	// biến đa năng
	// 1 - Start, 2 - Quit, 0 - Unknown, 3 - HELP game, 4 - About
	public int Command;
	public boolean IsMenu;

	public MyMenu(PhotoFrameCanvas photoCanvas) {
		this.photoCanvas = photoCanvas;
		Command = 0;
		IsMenu = true;
		Type = Main;

		try {

			Background = new MySprite(
					Image.createImage("/menu/PF_mainMenu.jpg"));
			Background.setRefPixelPosition(0, 0);

			BackgroundHelpAbout = new MySprite(
					Image.createImage("/PF_helpabout.jpg"));
			BackgroundHelpAbout.setRefPixelPosition(0, 0);

			Kid = new MySprite(Image.createImage("/menu/Kids.png"));
			Kid.setRefPixelPosition(120, 210);
			Flower = new MySprite(Image.createImage("/menu/Flowers.png"));
			Flower.setRefPixelPosition(74, 275);

			Exit = new MySprite(Image.createImage("/menu/Exit.png"));
			Exit.setRefPixelPosition(168, 360);

			About = new MySprite(Image.createImage("/menu/About.png"));
			About.setRefPixelPosition(55, 364);
			Help = new MySprite(Image.createImage("/menu/Help.png"));
			Help.setRefPixelPosition(0, 324);

			Back = new MySprite(Image.createImage("/Back_100x50.png"));
			Back.setRefPixelPosition(140, 350);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	// public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
	public void Draw(Graphics g) {
		switch (Type) {
		case MyMenu.Main: {

			Background.Draw(g);
			Kid.Draw(g);
			Flower.Draw(g);
			Exit.Draw(g);
			Help.Draw(g);
			About.Draw(g);
		}
			break;
		case MyMenu.HelpScreen: {

			BackgroundHelpAbout.Draw(g);
			Back.Draw(g);
			DrawHelp(g);
		}
			break;
		case MyMenu.AboutScreen: {

			BackgroundHelpAbout.Draw(g);
			Back.Draw(g);
			DrawAbout(g);
		}
			break;
		}
	}

	public void Update() {
		photoCanvas.repaint();
		System.out.print("Update Menu");
	}

	public void ProcessTap(int x, int y)
	// public void ProcessTap(Vector2 mousePos)
	{
		switch (Type) {
		case MyMenu.Main: {
			if (Kid.IsClicked(x, y))
				Command = 1;
			if (Flower.IsClicked(x, y))
				Command = 2;
			else if (Exit.IsClicked(x, y))
				Command = 3;
			else if (Help.IsClicked(x, y)) {
				Type = MyMenu.HelpScreen;
			} else if (About.IsClicked(x, y)) {
				Type = MyMenu.AboutScreen;
			}
		}
			break;
		case MyMenu.HelpScreen: {
			if (Back.IsClicked(x, y)) {
				Type = MyMenu.Main;
				Command = 0;
			}
		}
			break;
		case MyMenu.AboutScreen: {
			if (Back.IsClicked(x, y)) {
				Type = MyMenu.Main;
				Command = 0;
			}
		}
			break;
		}
		Update();
	}

	private void DrawAbout(Graphics g) {
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN
				| Font.STYLE_ITALIC, Font.SIZE_LARGE));
		g.setColor(255, 0, 0);
		g.drawString("Developer:", 30, 100, Graphics.TOP | Graphics.LEFT);
		g.drawString("Application name:", 30, 160, Graphics.TOP | Graphics.LEFT);
		g.drawString("Version:", 30, 220, Graphics.TOP | Graphics.LEFT);

		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD
				| Font.STYLE_ITALIC, Font.SIZE_LARGE));
		g.setColor(0, 150, 0);
		g.drawString("FCloud", 60, 120, Graphics.TOP | Graphics.LEFT);
		g.drawString("Photo Frame", 60, 180, Graphics.TOP | Graphics.LEFT);
		g.drawString("1.0.0", 60, 240, Graphics.TOP | Graphics.LEFT);

		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN
				| Font.STYLE_ITALIC, Font.SIZE_LARGE));
		g.setColor(255, 0, 0);
		g.drawString("Thanks for Using..!!", 30, 290, Graphics.TOP
				| Graphics.LEFT);
	}

	private void DrawHelp(Graphics g) {
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN
				| Font.STYLE_ITALIC, Font.SIZE_SMALL));
		g.setColor(0, 0, 0);		

		g.drawString("This is a Photo Frame app.", 25, 100, Graphics.TOP
				| Graphics.LEFT);
		g.drawString("Select picture from your 'Images'", 25, 125, Graphics.TOP
				| Graphics.LEFT);
		g.drawString("folder, and use this application", 25, 150, Graphics.TOP
				| Graphics.LEFT);
		g.drawString(" to make it more beatiful", 25, 175, Graphics.TOP
				| Graphics.LEFT);
		g.drawString("by adding frame to it.", 80, 200, Graphics.TOP
				| Graphics.LEFT);

		g.drawString("If you want to take new picture,", 25, 240, Graphics.TOP
				| Graphics.LEFT);		
		g.drawString("select frame category (Kid-Flower)", 25, 265,
				Graphics.TOP | Graphics.LEFT);
		g.drawString("and do whatever you want.", 25, 290, Graphics.TOP
				| Graphics.LEFT);
		
		g.drawString("Thanks for using.", 100, 315, Graphics.TOP
				| Graphics.LEFT);
		
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD
				| Font.STYLE_ITALIC, Font.SIZE_MEDIUM));
		g.setColor(0, 150, 0);
		g.drawString("Let's Enjoy..!!", 35, 340, Graphics.TOP | Graphics.LEFT);
	}
}
